/*
 * ImageAnimView.h
 *
 *  Created on: 2024年8月17日
 *      Author: ZKSWE Develop Team
 */

#ifndef _UI_IMAGE_ANIM_VIEW_H_
#define _UI_IMAGE_ANIM_VIEW_H_

#include "control/ZKBase.h"
#include "system/Thread.h"
#include "utils/BitmapHelper.h"
#include "utils/MessageQueue.h"

namespace ui {

typedef struct {
	uint16_t left;
	uint16_t top;
	uint16_t right;
	uint16_t bottom;
} region_t;

class ImageAnimView : public ZKBase, public Thread {
public:
	ImageAnimView(ZKBase *parent, int id, const LayoutPosition &pos);
	virtual ~ImageAnimView();

	bool load(const std::string &dir);
	void play(int index, bool sync = false);

protected:
	void procPlay(int index);
	void release();

	virtual void onDraw(ZKCanvas *pCanvas);
	virtual bool threadLoop();

	enum {
		E_MSG_PLAY,
		E_MSG_EXIT,
	};

private:
	bitmap_t *canvas_bmp_;
	bitmap_t img_bmp_;
	std::string dir_;
	Mutex lock_;
	MessageQueue msg_queue_;
	region_t dirty_;
	region_t *region_list_;
	uint32_t list_count_;
	int play_index_;
};

}

#endif /* _UI_IMAGE_ANIM_VIEW_H_ */
